package com.mmall.product;

import com.mmall.common.base.ServerResponse;
import com.mmall.common.util.ErrorUtil;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.ImportResource;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author guigu
 */
@SpringBootApplication
@EnableDiscoveryClient
@ServletComponentScan
@ImportResource(locations = {"classpath:druid-bean.xml"})
@ControllerAdvice
public class MmallProductApplication {

    public static void main(String[] args) {
        SpringApplication.run(MmallProductApplication.class, args);
    }

    /**
     * 全局异常处理
     *
     * @param ex Exception
     * @return R
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ServerResponse defaultExceptionHandler(Exception ex) {
        return ErrorUtil.handException(ex);
    }
}
